package ca.swank.hq;

import ca.swank.hardquor.*;

public class hqMove implements Cloneable
{

  public static final int WALL = 0;
  public static final int WALK = 1;
  public static final int NONE = 2;

  private hqBoardSquare source;
  private hqBoardSquare target;

  private hqBoardSquare a1;
  private hqBoardSquare a2;
  private hqBoardSquare b1;
  private hqBoardSquare b2;

  private int type;

  public hqMove(hqBoardSquare source, hqBoardSquare target)
  {
    this.source = source;
    this.target = target;
    type = WALK;

    a1 = null;
    a2 = null;
    b1 = null;
    b2 = null;

  }

  public Object clone()
  { hqMove dolly = new hqMove();
    if(source != null) dolly.source = (hqBoardSquare)source.clone();
    if(target != null) dolly.target = (hqBoardSquare)target.clone();
    if(a1 != null) dolly.a1 = (hqBoardSquare)a1.clone();
    if(a2 != null) dolly.a2 = (hqBoardSquare)a2.clone();
    if(b1 != null) dolly.b1 = (hqBoardSquare)b1.clone();
    if(b2 != null) dolly.b2 = (hqBoardSquare)b2.clone();
    dolly.type = type;
    return dolly;
  }

  public hqMove()
  { source = null;
    target = null;
    a1 = null;
    a2 = null;
    b1 = null;
    b2 = null;
    type = NONE;
  }

  public hqBoardSquare source()
  { return source;
  }

  public hqBoardSquare target()
  { return target;
  }


  public hqMove(hqBoardSquare a1, hqBoardSquare a2, hqBoardSquare b1, hqBoardSquare b2)
  {
	this.a1 = a1;
	this.a2 = a2;
	this.b1 = b1;
	this.b2 = b2;
	type = WALL;

	source = null;
	target = null;

  }

  public hqBoardSquare a1()
  { return a1;
  }

  public hqBoardSquare a2()
  { return a2;
  }

  public hqBoardSquare b1()
  { return b1;
  }

  public hqBoardSquare b2()
  { return b2;
  }

  public int type()
  { return type;
  }

  public int getDirectionA()
  {
	if(a1().x() - b1().x() == 1) // b left of a
	{ return hqBoard.DIR_LEFT;
	} else if(a1().x() - b1().x() == -1) // a left of b
	{ return hqBoard.DIR_RIGHT;
	} else if(a1().y() - b1().y() == 1) // a above b
	{ return hqBoard.DIR_BELOW;
	} else if(a1().y() - b1().y() == -1) // b above a
	{ return hqBoard.DIR_ABOVE;
    } else
    { return hqBoard.DIR_NONE;
    }
  }

  public int getDirectionB()
  { if(a1().x() - b1().x() == 1) // b left of a
	{ return hqBoard.DIR_RIGHT;
	} else if(a1().x() - b1().x() == -1) // a left of b
	{ return hqBoard.DIR_LEFT;
	} else if(a1().y() - b1().y() == 1) // a above b
	{ return hqBoard.DIR_ABOVE;
	} else if(a1().y() - b1().y() == -1) // b above a
	{ return hqBoard.DIR_ABOVE;
    } else
    { return hqBoard.DIR_NONE;
    }
  }

  public String toString()
  { String s = "UNDEFINED MOVE";
    if(type == WALL)
    { s = "WALL:  A = " + a1 + " , " + a2 + " B = " + b1 + " , " + b2;
    } else if(type == WALK)
    { s = "WALK:  SOURCE = " + source + " TARGET = " + target;
    }
    return s;
  }

}